package com.lazy.web.controller;

import com.github.pagehelper.PageInfo;
import com.lazy.core.entity.RunnerInfo;
import com.lazy.core.service.RunnerInfoService;
import com.lazy.utils.annotation.Access;
import com.lazy.utils.utils.Result;
import com.lazy.utils.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * 基础信息
 */
@RestController
@RequestMapping(value = "/runnerInfo")
public class RunnerInfoController {

    @Autowired
    RunnerInfoService runnerInfoService;


    @PostMapping(value = "/saveOrUpdate")
    public Result saveOrUpdate(RunnerInfo runnerInfo){
        int result = runnerInfoService.saveOrUpdate(runnerInfo);
        if(0 == result){
            return ResultUtils.errorResult();
        }else{
            return ResultUtils.successResult();
        }
    }

    @PostMapping(value = "/findByCondition")
    @Access
    public Result findByCondition(RunnerInfo runnerInfo,Integer pageNo,Integer pageSize){
        List<RunnerInfo> runnerInfos = runnerInfoService.findByCondition(runnerInfo,pageNo,pageSize);
        PageInfo<RunnerInfo> pageInfo = new PageInfo<>(runnerInfos);
        return ResultUtils.objectResult(pageInfo);
    }

    //创建Excel
    @RequestMapping("/exportRunnerInfo")
    @Access
    public void exportRunnerInfo(RunnerInfo runnerInfo,Integer pageNo,Integer pageSize) throws IOException {
        runnerInfoService.exportRunnerInfo(runnerInfo,pageNo,pageSize);
    }
}
